package com.darwin.darwinDll.analyze
{
	import com.darwin.darwinDisplay.DarXBitmapData;
	import com.darwin.darwinDll.core.DllItem;
	import com.darwin.darwinImage.darx.DarX;
	
	import flash.utils.ByteArray;
	import flash.utils.Dictionary;
	
	/**
	 *	DarX文件解析器 
	 * @author Roland
	 * 
	 */
	public class DarXAnalyze implements IAnalyze
	{
		private var _dic:Dictionary;
		public function DarXAnalyze()
		{
			super();
			_dic = new Dictionary();
		}
		
		public function analyze(byteArray:ByteArray, dllItem:DllItem, compFn:Function):void
		{
			if(_dic[dllItem.name] == null)
			{
				DarX.decode(byteArray,decodeComplete,false);
			}else{
				if(compFn != null)
				{
					compFn(dllItem);
				}
			}
			function decodeComplete(darxVec:Vector.<DarXBitmapData>):void
			{
				dllItem.data = byteArray;
				for (var i:int = 0; i < darxVec.length; i++) 
				{
					var darx:DarXBitmapData = darxVec[i];
					if(darx.subKey == null || darx.subKey == "")
					{
						darx.subKey = darx.key;
					}
					darx.key = dllItem.name.split("$")[0];
					_dic[darx.key + "$" + darx.subKey] = darx;
				}
				if(compFn != null)
				{
					compFn(dllItem);
				}
			}
		}
		
		public function getData(key:String, subKey:String):*
		{
			return _dic[key + "$" + subKey];
		}
		
		public function getDataList():Dictionary
		{
			return _dic;
		}
	}
}